//
//  StudentListTableViewCell.m
//  FaceRecognition
//
//  Created by zz on 16/12/6.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "StudentListTableViewCell.h"

@implementation StudentListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _avatar = [[UIImageView alloc] initWithFrame:CGRectMake(15, 9, 40, 40)];
        _avatar.layer.cornerRadius = 20;
        _avatar.contentMode = UIViewContentModeScaleAspectFill;
        _avatar.clipsToBounds = YES;
        [self.contentView addSubview:_avatar];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_avatar.frame) + 10, 20, 140, 19.5)];
        _nameLabel.font = [UIFont systemFontOfSize:18];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        [self.contentView addSubview:_nameLabel];
        
        _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH - 15 - 100 - 15, 22, 100, 14)];
        _countLabel.font = [UIFont systemFontOfSize:14];
        _countLabel.textColor = [UIColor colorWithHexString:@"#979797"];
        _countLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_countLabel];
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, 57.5, SCREENHEIGH - 15 - 15, 0.5)];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#DEDEDE"];
        [self.contentView addSubview:lineView];
    }
    
    return self;
}

- (void)setModel:(ManagerInfoModel *)model{
    
    _model = model;

    _nameLabel.text = model.studentname ? _model.studentname : _model.username;
    
    [self setlogo:_model.logo];
    
    _countLabel.text = [NSString stringWithFormat:@"%d张",_model.photocounts];
}

- (void)setlogo:(NSString *)logo{

    if (!logo) {
        
        return;
    }
    
    if (![logo hasPrefix:@"http"] && logo) {
        
        logo = [REQUESTIMAGEURL stringByAppendingString:logo];
    }
    
    [_avatar sd_setImageWithURL:[NSURL URLWithString:logo]];
}

- (void)setChildModel:(ManagerInfoModel *)childModel{
    
    _childModel = childModel;
    
    _nameLabel.text = childModel.studentname ? childModel.studentname : childModel.username;
    
    [self setlogo:childModel.logo];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
